#Twisted Shootout
#Copyright (C) 2007  Han Dao
#
#This program is free sself.sprites.add(s)oftware: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

#You can contact the author at wikipediankiba@gmail.com
import pygame
import data
import timer

class Enemy(pygame.sprite.Sprite):
	def __init__(self,w):
		pygame.sprite.Sprite.__init__(self)
		self.name , self.image = data.read.load("enemy")
		self.rect = self.image.get_rect()
		self.w = w
		self.retainer = [self.rect.x,self.rect.y]
		self.health = 5
		self.r = 0
		self.x = 0
		self.y = 0
		self.loc = 0
		self.turn = 0
		self.attack = 0
		self.status = False
		self.state = False
		self.orientation = 10
		self.between = 25
		self.collect = 0
	def move(self):
		self.flipwhen()
		self.jumpwhen()
		self.bullets()
		self.direction()
	def bullets(self):
		
			if self.attack != 0:
				if self.attack == self.r:
					self.w.enemyfire(self.rect.x,self.rect.y,self.orientation)
					self.attack = -1
			if self.attack == -1:
				if self.collect == self.between:
					self.collect = 0 
					self.w.enemyfire(self.rect.x,self.rect.y,self.orientation)
				self.collect = self.collect + 1
	def flipwhen(self):
		if self.turn != 0:
			if self.turn == self.r:
				self.flip()
	def direction(self):
		if self.state == 1:
			self.rect.x = self.rect.x + 5
		elif self.state == 2:
			self.rect.x = self.rect.x - 5
		if self.r != 0:
			self.r = self.r - 1
			if self.r == 0:
				self.state = False
	def jumpwhen(self):
		if self.loc != 0:
			if self.loc == self.r:
				self.jump()
				self.loc = -1
			elif self.loc == -1:
				self.jump()
	def jump(self):
		if self.status == True:
			self.rect.y = self.rect.y - 5
			self.y = self.y - 5
			if self.y == -100:
				self.status = 10
		elif self.status == 10:
			self.y = self.y + 5
			if self.y == 0:
				self.status = False
	def up(self,loc = 0):
		if self.status == True:
			return
		elif self.status == 10:
			return
		self.status = True
		self.loc = loc
	def changemove(self,r,state):
		self.r = r
		self.state = state
	def changeflip(self,turn = 0):
		self.turn = turn
	def flip(self):
		self.image = pygame.transform.flip(self.image, True, False)
		if self.orientation == 10:
			self.orientation = -10
		elif self.orientation  == -10:
			self.orientation = 10
	def shoot(self,attack = 0):
		self.attack = attack